from typing import List
class Solution:#压缩栈
    def findkthlargest(self,nums:List[int],k:int)->int:
        stack=[]
        for num in nums:
            if len(stack)<k:
                i=0
                while i<len(stack) and stack[i]<num:
                    i+=1
                stack.insert(i,num)
            else:
                if num>stack[0]:
                    stack.pop(0)
                    i=0
                    while i<len(stack) and stack[i]<num:
                        i+=1
                    stack.insert(i,num)
        return stack[0]
if __name__=='__main__':
    solution=Solution()
    nums = [3, 2, 1, 5, 6, 4]
    k=2
    print(f'数组{nums},k={k}')
    print(f'第{k}个最大元素是：{solution.findkthlargest(nums,k)}')